/**
 * numberMovePoint 移动数数字的小数点位置
 * @param {number} number 原始数字, 大于0
 * @param {number} move 偏移位数, 正数向右, 负数向左, 0不动
 * @param {boolean} float 偏移后是否返回浮点数, 默认返回整数
 * @returns {number} 返回便宜过小数点的数字
 */
export default function numberMovePoint({ number, move = 2, float }) {
  if (number <= 0) {
    throw "argument value error: number must greater than 0";
  }
  const re = /^[0-9]+.?[0-9]*$/;
  if (!re.test(number)) {
    throw "argument type error: number must be a Number";
  }
  const __move = Number.parseInt(move);
  if (isNaN(__move)) {
    throw "argument type error: move must be a Number";
  }
  const _move = Math.abs(__move);
  const fixZero = new Array(_move).fill("0").join("");
  if (__move === 0) {
    if (float) {
      return Number.parseFloat(number);
    }
    return Number.parseInt(number);
  }
  if (__move > 0) {
    let [a, b] = `${number}${fixZero}`.split(".");
    if (b) {
      a += b.slice(0, __move);
    }
    if (float) {
      return Number.parseFloat(a);
    }
    return Number.parseInt(a);
  }
  let [a, b] = `${fixZero}${number}`.split(".");
  a = a.slice(0, __move) + "." + a.slice(__move) + b;
  if (float) {
    return Number.parseFloat(a);
  }
  return Number.parseInt(a);
}
